import { useSelector, shallowEqual } from "react-redux";
import http from "utils/http";
import { cleanObject } from "utils";

export default function useHttp() {
  const { token } = useSelector(
    (state) => ({
      token: state.getIn(["user", "token"]),
    }),
    shallowEqual
  );

  const $get = (url, data={}) => {
    return http.get(url, {
      params: cleanObject(data),
      headers: { Authorization: "Bearer " + token },
    });
  };
  const $post = (url, data={}) => {
    return http.post(url, cleanObject(data), {
      headers: { Authorization: "Bearer " + token },
    });
  };

  
  return {
    $get,
    $post,
  };
}
